﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.ComponentModel;


namespace postSale.Controls
{
    public class gridIMaintenanceHistory : common.controls.baseDataGridView 
    {
        public enum ColumnNames
        {
            onDate, problem, repairDesc, repairBy, notes 
        };

        public gridIMaintenanceHistory()
        {
        }

        public override void Init(BindingSource dataSource)
        {
            base.Init(dataSource);
            data.postSaleDS.maintenanceHistoryDataTable detailTbl = (data.postSaleDS.maintenanceHistoryDataTable)dataSource.DataSource;
            // 
            // onDate
            // 
            DataGridViewCellStyle dateCellStyle = new DataGridViewCellStyle();
            dateCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dateCellStyle.Format = "d";
            dateCellStyle.Format = "d";

            common.controls.DataGridViewTextBoxColumnExt onDate = new common.controls.DataGridViewTextBoxColumnExt();
            onDate.DataPropertyName = detailTbl.onDateColumn.ColumnName;
            onDate.HeaderText = "Ngày";
            onDate.Name = ColumnNames.onDate.ToString();
            onDate.Width = 90;
            onDate.Uppercase = true;
            onDate.DefaultCellStyle = dateCellStyle;

            // 
            // problem
            // 
            common.controls.DataGridViewTextBoxColumnExt problem = new common.controls.DataGridViewTextBoxColumnExt();
            problem.DataPropertyName = detailTbl.problemColumn.ColumnName;
            problem.HeaderText = "Vấn đề";
            problem.Name = ColumnNames.problem.ToString();
            problem.Width = 100;
            problem.Uppercase = true;

            // 
            // repairDesc
            // 
            DataGridViewTextBoxColumn repairDesc = new DataGridViewTextBoxColumn();
            repairDesc.DataPropertyName = detailTbl.repairDescColumn.ColumnName;
            repairDesc.HeaderText = "Sửa chữa";
            repairDesc.Name = ColumnNames.repairDesc.ToString();
            repairDesc.Width = 200;
            // 
            // repairBy
            // 
            DataGridViewTextBoxColumn repairBy = new DataGridViewTextBoxColumn();
            repairBy.DataPropertyName = detailTbl.repairedByColumn.ColumnName;
            repairBy.HeaderText = "Sửa chữa";
            repairBy.Name = ColumnNames.repairBy.ToString();
            repairBy.Width = 200;

            // 
            // Notes
            // 
            DataGridViewTextBoxColumn notes = new DataGridViewTextBoxColumn();
            notes.DataPropertyName = detailTbl.notesColumn.ColumnName;
            notes.HeaderText = "Ghi chú";
            notes.Name = ColumnNames.notes.ToString();
            notes.Width = 110;

            // 
            // myDetailGrid
            // 
            this.Visible = true;
            this.DataSource = dataSource;

            this.ReadOnly = false;
            this.ScrollBars = ScrollBars.Vertical;
            this.AutoGenerateColumns = false;
            this.Columns.Clear();
            this.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {onDate,problem,repairDesc,repairBy,notes});
            this.myAutoFitColumn = ColumnNames.problem.ToString();
            this.DisbaleReadOnlyColumns();
        }
        protected override void OnDefaultValuesNeeded(DataGridViewRowEventArgs e)
        {
            base.OnDefaultValuesNeeded(e);
            if (e == null) return;
            if (myDataSource.Current != null)
                DataAccess.DataLibs.InitData((data.postSaleDS.maintenanceHistoryRow)((DataRowView)myDataSource.Current).Row);
        }
    }
}
